package 所有的题类.F.树;

import 所有的题类.ZA.链表.TreeNode;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class 二叉树的右视图 {

    public static void main(String[] args) {
        TreeNode root=new TreeNode(1);
        TreeNode left=new TreeNode(2);
        TreeNode right=new TreeNode(3);
        TreeNode gui=new TreeNode(3);

    }

    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> list= new ArrayList();
        Deque<TreeNode> deque = new LinkedList();
        deque.add(root);
        while(deque.size()>0){
            list.add(deque.getFirst().val);
            int size=deque.size();
            for(int i=0;i<size;i++){
                TreeNode node=deque.poll();
                if(node.right!=null){
                    deque.add(node.right);
                }
                if(node.left!=null){
                    deque.add(node.left);
                }
            }
        }
        return list;
    }
}
